//
//  BCWalletCell.m
//  GSBlockChain
//
//  Created by guoshikeji_a on 2018/11/23.
//  Copyright © 2018年 guoshikeji. All rights reserved.
//

#import "BCWalletCell.h"


CGFloat const BCWalletCellLeftPadding = 20.0f;
CGFloat const BCWalletCellRightPadding = 20.0f;

@interface BCWalletCell ()

@property (nonatomic, strong) UILabel *coinTypeLabel;

@property (nonatomic, strong) UILabel *totleValueLabel;

@property (nonatomic, strong) UILabel *coinLabel;

@end

@implementation BCWalletCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupSubviews];
    }
    return self;
}

- (void)setupSubviews {
    self.coinTypeLabel = [UILabel new];
    self.coinTypeLabel.adjustsFontSizeToFitWidth = true;
    [self.contentView addSubview:self.coinTypeLabel];
    //
    UIView *preferenceView = [UIView new];
    [self.contentView addSubview:preferenceView];
    
    //
    self.totleValueLabel = [UILabel new];
    self.totleValueLabel.adjustsFontSizeToFitWidth = true;
    [self.contentView addSubview:self.totleValueLabel];
    //
    self.coinLabel = [UILabel new];
    self.coinLabel.adjustsFontSizeToFitWidth = true;
    [self.contentView addSubview:self.coinLabel];
    //
    [self.coinTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView).offset(BCWalletCellLeftPadding);
        make.centerY.mas_equalTo(self.contentView);
        make.width.mas_equalTo(50.0);
    }];
    [preferenceView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.coinTypeLabel.mas_right).offset(25.0);
        make.right.mas_equalTo(self.contentView);
        make.centerY.mas_equalTo(self.contentView);
        make.height.mas_equalTo(self.contentView);
    }];
    [self.totleValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(preferenceView);
        make.centerY.mas_equalTo(self.contentView);
        make.right.mas_equalTo(preferenceView.mas_centerX).offset(-10.0);
    }];
    [self.coinLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(preferenceView.mas_centerX);
        make.right.mas_equalTo(self.contentView).offset(-10.0);
        make.centerY.mas_equalTo(self.contentView);
    }];
    //
    [self addSubview:self.separatorLine];
    [self.separatorLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self);
        make.left.mas_equalTo(self).offset(10.0);
        make.right.mas_equalTo(self).offset(-10.0);
        make.height.mas_equalTo(1);
    }];
}

- (void)setIsTitle:(BOOL)isTitle {
    _isTitle = isTitle;
    //
    UIColor *textColor = isTitle?[UIColor qmui_colorWithHexString:@"#333333"]:[UIColor qmui_colorWithHexString:@"#666666"];
    self.coinTypeLabel.textColor = self.totleValueLabel.textColor = self.coinLabel.textColor = textColor;
    //
    UIFont *textFont = isTitle?[UIFont systemFontOfSize:15 weight:UIFontWeightMedium]:[UIFont systemFontOfSize:16 weight:UIFontWeightRegular];
    self.coinTypeLabel.font = self.totleValueLabel.font = self.coinLabel.font = textFont;
    
//    //
//    if (isTitle) {
//        self.coinTypeLabel.text = @"币种";
//        self.totleValueLabel.text = @"总市值(USD)";
//        self.coinLabel.text = @"余额";
//    }else {
//        self.coinTypeLabel.text = @"BTC";
//        self.totleValueLabel.text = @"108.25";
//        self.coinLabel.text = @"211.02359475";
//    }
}

- (void)setWalletData:(BCUserWalletData *)walletData {
    _walletData = walletData;
    //
    self.coinTypeLabel.text = walletData.flow.curs;
    self.totleValueLabel.text = [walletData.flow.market stringByReplacingOccurrencesOfString:@"{}" withString:walletData.monetaryUnit];
    self.coinLabel.text = walletData.flow.balance;
}

- (void)setBalance:(BCUserWalletDataBalance *)balance monetaryUnit:(NSString *)monetaryUnit{
    self.balance = balance;
    self.coinTypeLabel.text = balance.acronyms;
    self.totleValueLabel.text = [NSString stringWithFormat:@"%@",[balance.market objectForKey:monetaryUnit]];
    self.coinLabel.text = balance.money;
}

+ (CGFloat)defaultHeight {
    return 44.0;
}
@end
